/**
 * Action object
 *
 */

var actions = {
  array: []
};
  
function Action(name, img) {
  this.name = name;
  this.img = img;
  
  /* Create the Actions Element */
  this.act = document.createElement('div');
  this.act.setAttribute('class', 'action');
  var img = document.createElement('img');
  img.setAttribute('src', this.img.src);
  this.act.appendChild(img);
  this.act.appendChild(document.createTextNode(this.name));
  
  /* Register event listeners */
  var obj = this;
  if (this.act.attachEvent) {
    this.act.attachEvent('onclick', function(event){obj.onmouseclick(event)});
  } else {
    this.act.addEventListener('click', function(event){obj.onmouseclick(event)}, false);
  }
  
  actions.array[actions.array.length] = this;
};

/**
 * Shows this Action on screen. 
 *
 */
Action.prototype.showAction = function(el) {
  el.appendChild(this.act);
};

Action.prototype.onmouseclick = function(event) {
  for (var i = 0; i < actions.array.length; i++)
    actions.array[i].act.style.backgroundColor = '#a5adf3';
  this.act.style.backgroundColor = '#555da3';
};